﻿using System;
using System.Configuration;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Function.Arithmetics {
    public class FpprecNode : FuncNode {

        public string Precision {
            get {
                return ConfigurationManager.AppSettings["Precision"];
            }
            set {
                ConfigurationManager.AppSettings["Precision"] = value.ToString();
            }
        }

        public FpprecNode()
            : base() {
            base.Value = "prec";
        }

        public override object Evaluate() {
            if (Parameters.Count < 0) {
                throw new ArgumentException("Usage: prec() | prec(number)");
            }

            if (Parameters.Count > 0) {
                Utils.Precision = Convert.ToInt32(Parameters[0].Evaluate());
            }

            return Utils.Precision;
        }
    }
}
